package engine.newUi
{
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.tip.TipsMainLogic;
	import engine.ui.lite.BaseUI;
	
	import flash.events.MouseEvent;
	
	import newx.com.config.StaticIni;
	import newx.com.control.button.NxButton;
	import newx.com.control.text.NxLabel;
	
	public class DrawInfoUI extends BaseUI
	{
		public var infoTxt		:NxLabel;
		public var sureBtn		:NxButton;
		public var changeBtn	:NxButton;
		private var _backFun	:Function;
		private var _model		:ModelLocator
		private var _vipLevel	:int;
		private var _changeLuckStatus:int;
		private static var _self:DrawInfoUI;
		private var _isOK:Boolean = false;  
		public function DrawInfoUI(popupUI:Boolean=true)
		{
			super(popupUI);
		}
		public static function getInstance():DrawInfoUI
		{
			if(_self == null)
			{
				_self	=	new DrawInfoUI();
			}
			return _self;
		}
		
		override public function Init():void
		{
			_model	=	ModelLocator.getInstance();
			//查寻所需要的消耗信息
			_model			.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_CHANGE_LUCK_CIMILIA_COMSUME ),needMoney);
			BindManage.getInstance().BindProp(_model.scene.Role,"VIPLevel",this,"vipLevel");
			BindManage.getInstance().BindProp(_model.scene.Role,"ChangeLuckStatus",this,"changeLuckStatus");
		}
		/**
		 * 
		 * @param index 1,2,3,4,5 图片的顺序
		 * @param type  0 ，1 是否需要显示再换一张
		 * @param backFunction 回调函数 function (val :int) 0:sure ; 1:again
 		 * 
		 */		
		public function showInfo(index:int,type:int,backFunction:Function):void
		{
			infoTxt.htmlText	=	getStr(index);
			_backFun	=	backFunction;
			if(type == 0 || type == 2)
			{
				sureBtn.x			=	120;
				changeBtn.visible	=	false
			}
			else
			{ 
				if(_vipLevel >= 3 && _changeLuckStatus == 0 )
				{
					sureBtn.x			=	78;
					changeBtn.visible	=	true;
				}
				else
				{
					sureBtn.x			=	120;
					changeBtn.visible	=	false;
				}

			}
			this.show(DrawPictureUI.getInstance().windowBG);
			
		}
		/**
		 * 设定VIP等级
		 */		
		public function set vipLevel(val:int):void
		{
			_vipLevel	=	val
		}
		public function set changeLuckStatus(val:int):void
		{
			_changeLuckStatus	=	val;
		}
		/**
		 * 所需要的消耗
		 * @param e
		 * 
		 */		
		private function needMoney(e:CustomMsgEvent):void
		{
			TipsMainLogic.instance.showMain(StaticIni.getSwfLangStrVar("99170",[e.pList[0]]));
		}
		private function addListent():void
		{
			sureBtn.addEventListener(MouseEvent.CLICK, 			clickHandle);
			changeBtn.addEventListener(MouseEvent.CLICK, 		clickHandle);
			changeBtn.addEventListener(MouseEvent.MOUSE_OVER, 	overHandle);
			changeBtn.addEventListener(MouseEvent.MOUSE_OUT, 	outHandle);
		}
		private function removeListent():void
		{
			sureBtn.removeEventListener(MouseEvent.CLICK, 			clickHandle);
			changeBtn.removeEventListener(MouseEvent.CLICK, 		clickHandle);
			changeBtn.removeEventListener(MouseEvent.MOUSE_OVER,	overHandle);
			changeBtn.removeEventListener(MouseEvent.MOUSE_OUT, 	outHandle);
		}
		private function clickHandle(e:MouseEvent):void
		{
			var target:NxButton	=	e.currentTarget	as NxButton;
			switch(target)
			{
				case sureBtn:
					_backFun.call(this,0);
					_isOK=true;  
					break;
				case changeBtn:
					
					_backFun.call(this,1);
					break;
			}
			removeListent()
		}
		private function overHandle(e:MouseEvent):void
		{
			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLEINT_CUSTOMMSG_CHANGE_CIMILIA_COMSUME);
		}
		private function outHandle(e:MouseEvent):void
		{
			TipsMainLogic.instance.hide();
		}
		/**
		 * 获取显示信息 
		 * @param val
		 * @return 
		 * 
		 */		
		private function getStr(val:int):String
		{
			var returnStr:String	=	StaticIni.getSwfLangStrVar("UIString_1000407",[getPicName(val),getReput(val)]);
			return returnStr;
		}
		/**
		 * 可获得的声望 
		 * @param val
		 * @return 
		 * 
		 */		
		public function getReput(val:int):int
		{
			var returnInd:int	=	0
			switch(val)
			{
				case 1:
					returnInd	=	10;
					break;
				case 2:
					returnInd	=	100;
					break;
				case 3:
					returnInd	=	300;
					break;
				case 4:
					returnInd	=	1000;
					break;
				case 5:
					returnInd	=	2000;
					break;
			}
			return returnInd;
		}
		/**
		 * 对因图片的类型 
		 * @param val
		 * @return 
		 * 
		 */		
		public function getPicName(val:int):String
		{
			var returnStr:String	=	"";
			switch(val)
			{
				case 1:
					returnStr	=	StaticIni.getSwfLangStr("UIString_1000408");
					break;
				case 2:
				case 3:
				case 4:
					returnStr	=	StaticIni.getSwfLangStr("UIString_1000409");
					break;
				case 5:
					returnStr	=	StaticIni.getSwfLangStr("UIString_1000410");
					break;
			}
			return returnStr;
		}
		override protected function BeforeShow():void
		{
			addListent();
		}
		override protected function AfterHide():void
		{
			removeListent();
		}
		public function get isOk():Boolean
		{
			return _isOK
		}
		public function set isOk(value:Boolean):void
		{
			_isOK  =  value ; 
		}
	}
}